/**
 * Created by liujie on 2017/11/6.
 */
/**
 * Created by liujie on 2017/10/21.
 */
var FastAddDeviceInfo = function ($) {
    var viewAddPage_url = "/editFastDeviceInfo/addData";
    var viewAccountList_url = "/deviceManage";
    function initTable() {
        var dataTable = new BootstrapTable($('#roleTable'),{
            url: '/roleManage/queryRoleList',
            sidePagination: "client",
            toolbar: '#toolbar',
            columns: [{
                checkbox: true
            }, {
                field: 'roleName',
                title: '角色名称'
            }, {
                field: 'empName',
                title: '所属用户'
            }]
        });
        dataTable.init();
    }


    /**
     * 初始化用户管理编辑页面事件
     */
    function initEditUserInfoEvent() {
        $("#submitForm").on("click",function () {
            if($("#baseTerminalId").val() == ""){
                $.messageExt.alert("系统提示","设备编号为必填项！","error");
                return false
            }
            if($("#baseTerminalSim").val() == ""){
                $.messageExt.alert("系统提示","SIM卡号为必填项！","error");
                return false
            }
            if($("#baseProtocolType").val() == ""){
                $.messageExt.alert("系统提示","设备型号为必填项！","error");
                return false
            }
            $.ajax({
                url:viewAddPage_url,
                type:"POST",
                data:{
                    deptId:0,
                    baseTerminalId:$("#baseTerminalId").val(),
                    baseTerminalSim:$("#baseTerminalSim").val(),
                    baseProtocolType:$("#baseProtocolType").val()
                },
                dataType:"json"
            }).done(function (result) {
                if(result.isSuccess === true){
                    $.messageExt.alert("系统提示","设备添加成功！","success");
                    $("#baseTerminalId").val("");
                    $("#baseTerminalSim").val("")
                }else{
                    $.messageExt.alert("系统提示",result.message?result.message:"保存失败！","error");
                }
            })
        });
        $("#back-view").click(function () {
            $.link(viewAccountList_url);
        });
        $("#userInfoForm").validForm([
            {
                name:"baseTerminalId",
                validate:{
                    type:"require",
                    message:"设备编号是必填项"
                }
            },
            {
                name:"baseTerminalSim",
                validate:[
                    {
                        type:"require",
                        message:"SIM卡号为必填项"
                    }
                ]
            }
        ])
    }

    return{
        initEditRolePage:function () {
            initEditUserInfoEvent();
        }
    }
}(jQuery);